﻿@using MiniFox.Platform.OAuth2.Models
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    var changepwd = Url.Content("~/authorization/changepassword");
}
@model ChangePassword
@section head {
    <title>修改密码</title>
    <script>

        $(function () {
            var service = MiniFox.createService({
                "defaults": {
                    "host": {
                        "OAUTH2": "",
                        "BASE": "",
                        "validation": ""
                    },
                    "autoMsg": false,
                    "timeOut": 120000,
                    "enableCookies": false,
                    "method": "post"
                },
                "adapters": [
                    {
                        "name": "oauth2",
                        "host": "OAUTH2",
                        "virtualPath": "",
                        "api": [
                            {
                                "name": "changePwd",
                                "url": "@(changepwd)",
                                "enableCookies": false,
                                "showProcessing": true,
                                "autoMsg": true,
                                "method": "post"
                            }
                        ]
                    }
                ]
            });
            var reset = function () {

                $("#btn_save").button('reset');
                $("#form").find("input").removeAttr("disabled");
            };
            $("#btn_reset").click(function(){
                $("#form").find("input").val('');
            });

            $("#btn_save").click(function () {
                var postData = {
                    password: $('#Password').val(),
                    newPassword: $('#NewPassword').val(),
                    confirmPassword: $('#ConfirmPassword').val(),
                };
                service.oauth2.changePwd({
                    data: postData,
                    beforeSend: function (xhr) {
                        $("#btn_save").button('loading');
                        $("#form").find("input").attr("disabled", "disabled");
                        return true;
                    },
                }).then(function (response) {
                    if (response.success)
                        $("#btn_reset").click();
                    reset();
                }).catch(function () {
                    reset();
                });
            });
        });
    </script>
}
@section toolbar {
    <button id="btn_save" onclick="return false;" class="btn btn-primary btn-sm"><i class="glyphicon glyphicon-save"></i> 保存</button>
    <button id="btn_reset" onclick="return false;" class="btn btn-primary btn-sm"><i class="glyphicon glyphicon-repeat"></i> 重置</button>
}

<form id="form" class="form-horizontal" style="width:600px; margin:30px auto" name="form" role="form" action="@changepwd" commitbutton="btn_save" method="POST">
<div class="row form-group form-group-sm has-feedback">
    <div class="col-sm-2">
        @Html.LabelFor(m => m.Password, new { Class = "control-label" })
    </div>
    <div class="col-sm-5">
        @this.Html.PasswordFor(m => m.Password, new { Class = "form-control", placeholder = "请输入原密码", aria_describedby = "des_OldPassword" })

        <span class="glyphicon glyphicon-info-sign form-control-feedback" aria-hidden="true"></span>

    </div>
    <div class="col-sm-5">
        @Html.DescriptionFor(m => m.Password, new { Class = "help-block", id = "des_OldPassword" })
    </div>
</div>
<div class="row form-group form-group-sm has-feedback">
    <div class="col-sm-2">
        @Html.LabelFor(m => m.NewPassword, new { Class = "control-label" })
    </div>
    <div class="col-sm-5">
        @this.Html.PasswordFor(m => m.NewPassword, new { Class = "form-control", placeholder = "请输入新密码", aria_describedby = "NewPassword" })

        <span class="glyphicon glyphicon-info-sign form-control-feedback" aria-hidden="true"></span>
    </div>
    <div class="col-sm-5">
        @Html.DescriptionFor(m => m.NewPassword, new { Class = "help-block", id = "des_NewPassword" })
    </div>
</div>
<div class="row form-group form-group-sm">
    <div class="col-sm-2">
        @Html.LabelFor(m => m.ConfirmPassword, new { Class = "control-label" })
    </div>
    <div class="col-sm-5">
        @this.Html.PasswordFor(m => m.ConfirmPassword, new { Class = "form-control", placeholder = "请确认新密码" })
    </div>
    <div class="col-sm-5">
    </div>
</div>
</form>